/**
 * 圆上的点的坐标
 */
const circlePoint = (cx, cy, r) => angle => {
  const cos = Math.cos;
  const sin = Math.sin;
  const PI = Math.PI;
  const x = cx + r * cos((angle * PI) / 180);
  const y = cx + r * sin((angle * PI) / 180);
  return { x, y };
};

/**
 * 径向移动
 * @param {Number} cx - 圆心x坐标
 * @param {Number} cy - 圆心y坐标
 * @param {Number} r - 移动半径
 * @param {Array} source - 数据源
 */
export default function radialMove({ cx, cy, r, source }) {
  const getPosition = circlePoint(cx, cy, r);
  const len = source.length;

  return source.map((item, index) => {
    const angle = Math.floor(360 / len);
    const { x, y } = getPosition(index * angle);
    return { ...item, mx: x - cy, my: y - cy };
  });
}
